-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow optimistic mirror of kbuckets with read lock only #229
Conversation
e1cc1b9
to
a29538d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Emilia, doesn't the kbuckets
function cover these usecases?
hey :) one of them, yes true, also it occurred to me, a |
but Regarding little as memory, a |
but it only clones the node id (32 bytes) and not the enr (up to 300 bytes encoded length) for each entry
I want to use this api in reth, using minimal resources is baseline for all client development. |
/// .map(|entry| *entry.node.key.preimage()) | ||
/// .collect::<Vec<_>>()); | ||
/// ``` | ||
pub fn with_kbuckets<F, T>(&self, f: F) -> T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced the methods for this one which covers all cases
The idea is to not Clone the kbuckets table right? I was thinking about this, and the data structure for kbuckets ins't great. But I estimate in most cases, we usually have a couple of buckets full, then the rest dying off. So we probably have like 50 ENRs in a table. If they are maxed out that's like 300 bytes per ENR which is like 15kb per table. So worst case we are prob copying 15kb in memory, which isn't too bad imo, but I can see the desire to avoid the clone. I think in this case, an easy solution would be just to expose I think the original problem with exposing this, is that the public API is then tagged to the Arc and the exact version of parking_lot that exposes RwLock, so we'd have to re-export parking_lot. As this current PR exposes this now anyway, maybe we just expose self.kbuckets? Will that satisfy all the requirements you need? |
totally agree, I changed the code in this pr to do that yesterday |
Yeah, so what about something like this?: /// Returns the routing table of the discv5 service
pub fn kbuckets_arc(&self) -> Arc<RwLock<KBucketsTable<NodeId, Enr>> {
self.kbuckets.clone()
} |
the code I have made is essentially the same thing, besides it's safer, since any lock taken is at least dropped at the end of closure. |
Yeah, this api has a few downsides:
I don't mind adding it in, if you really need it. The downside of putting a closure into the API, is that its now limited to a I'm not sure other people should use this for the downsides above. But if you need it in reth, happy to add it in. |
the same goes for the sure it exposes the specific parking lot version. this api allows to call
yes, In the docs I added a note on the user's responsibility to drop the lock. the risk is in practice minimised by locking in a closure's scope like this in my experience.
it would be very useful to have that flexibility. I could even feature gate it if you like, have some feature called "dev-mode", wdyt?
to take a read or write lock we just need a ref to self
that would be great, thanks. |
Description
allows optimistic and less blocking interaction with discv5
Notes & open questions
Change checklist